<template>
  <div class="SelectUnit">
    <NavBar
      fixed
      placeholder
      title="施工单位"
      z-index="999"
      @click-right="onClickRight"
      ref="nav"
    >
      <template #left>
        <Icon
          name="arrow-left"
          size="0.53rem"
          color="#333333"
          @click="$router.back()"
        />
      </template>
    </NavBar>
    <Search
      v-model="search"
      background="#e1e1e1"
      placeholder="请输入搜索关键词"
      show-action
      @search="onSearch"
      @cancel="onCancel"
    />

    <List
      class="list"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div
        class="item"
        v-for="(item, i) in list"
        :key="i"
        @click="toJump(item)"
      >
        <div class="title flex">
          <img src="../../../assets/img/unit.png" alt="" />
        </div>
        <div class="name">{{ item.dcuNam }}</div>
      </div>
    </List>
  </div>
</template>

<script>
import { ConstructionUnitList } from "../../../api/work.js";
import { Search, NavBar, Icon, List, Cell } from "vant";
export default {
  props: {},
  data() {
    return {
      search: "",
      list: [],
      loading: false,
      finished: false,
      pageNum: 1,
      pageSize: 10,
    };
  },

  created() {},
  mounted() {},
  watch: {},
  methods: {
    async onLoad() {
      const data = await ConstructionUnitList({
        dcuNam: this.search,
        pageNo: this.pageNum,
        pageSize: this.pageSize,
      });
      console.log(data.value);
      this.list.push(...data.value);
      this.loading = false;
      if (this.list.length < this.pageSize * this.pageNum) {
        this.finished = true;
      }
      this.pageNum++;
    },
    onClickRight() {},
    onSearch() {},
    onCancel() {},
    toJump(item) {
      console.log(item);
      let query = {
        ...this.$route.query,
        ...item,
      };
      this.$router.push({
        path: "JobDetailsNext",
        query,
      });
    },
  },
  components: { Search, NavBar, Icon, List, Cell },
};
</script>

<style scoped lang="less">
@import "~@/style/var.less";
.SelectUnit {
  .flex {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  background-color: #f7f7f9;
  // /deep/.van-nav-bar__content {
  //   background-color: #3982f6;

  //   .van-nav-bar__title {
  //     color: #fff;
  //   }
  // }
  .list {
    margin-top: 20px;

    .item {
      width: 100%;
      height: 98px;
      border-top: 1px solid #eee;
      background-color: #fff;
      display: flex;
      align-items: center;
      .title {
        width: 52px;
        height: 52px;
        background: @primary;
        border-radius: 50%;
        font-size: 28px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #ffffff;
        margin-left: 23px;
        img {
          width: 55%;
        }
      }
      .name {
        margin-left: 31px;
        font-size: 28px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666666;
      }
    }
  }
}
</style>
